package com.education.service.job;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 余一
 * @Description
 * @date 2021/6/13 17:18
 */
@Configuration
public class JobBeanConfig {

    private static final String DEFAULT_GROUP = "default_group";

    //创建JobDetail对象
    @Bean
    public JobDetail systemJob(){
        return JobBuilder.newJob(SystemJob.class)
            .withIdentity(SystemJob.class.getSimpleName(),DEFAULT_GROUP).storeDurably().build();
    }
    //创建任务触发器
    @Bean
    public Trigger jobTrigger(){
        return TriggerBuilder.newTrigger().forJob(systemJob().getKey())
                .withIdentity(SystemJob.class.getSimpleName(),DEFAULT_GROUP)
                .startNow().withSchedule(CronScheduleBuilder.cronSchedule("*/5 * * * * ?")).build();
    }



}
